<template>
	<view class="m30">
		<view class="content-box f26">
			<u-parse :content="detail.content"></u-parse>
		</view>
		<u-gap height="20"></u-gap>
		<view class="" v-if="detail.coupId">
			<u-button shape="circle" :disabled="detail.isGetCoup == 1" color="#FFDE6D" @click="receiveCoupon"
				:customStyle="{'color':'#34314F','border':'1px solid #FFDE6D','height':'70rpx'}">
				{{detail.isGetCoup == 1?'您已领取优惠券':'领取优惠券'}}
			</u-button>
		</view>
	</view>
</template>

<script>
	import appInfo from '@/common/appInfo.js'
	import {getNoticeinfo} from '@/common/api_user.js'
	import {receiveCoupon} from '@/common/api_housekeeping.js'
	export default {
		name: '',
		data() {
			return {
				coidde:'',
				detail:{}
			}
		},
		onLoad(option) {
			this.id = option.id
			this.getNoticeinfo()
		},
		methods: {
			async getNoticeinfo(){ //购买须知
				uni.showLoading({
					mask:true
				})	
				const res = await getNoticeinfo({
					id:this.id
				})
				if(res.code == 200){
					this.detail = res.data
					uni.setNavigationBarTitle({
						title:this.detail.title
					})
				}
				uni.hideLoading()
			},
			async receiveCoupon(){
				// #ifdef MP-WEIXIN
				let messageRes = await this.$utils.messageSubscriptionAuthorization(appInfo.tmplIds.coupon);
				// #endif
				uni.showLoading({
					mask:true
				})	
				const res = await receiveCoupon({
					id:this.detail.coupId
				})
				if(res.code == 200){
					uni.showToast({
						title:'领取成功',
						icon:"none"
					})
					this.detail.isGetCoup = 1
					//this.getNoticeinfo()
				}
				uni.hideLoading()
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FEF4E8;
	}
	
</style>